package com.onehouse.infrastructure.repository.checkIn;

import com.onehouse.domain.checkIn.adapter.repository.ICheckInRoomPriceRepository;
import com.onehouse.infrastructure.dao.RoomPriceDao;
import com.onehouse.infrastructure.dao.RoomTypeDao;
import com.onehouse.infrastructure.dao.po.RoomPrice;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.time.LocalDate;

@Repository
public class CheckInRoomPriceRepository implements ICheckInRoomPriceRepository {

    @Resource
    private RoomPriceDao roomPriceDao;

    @Resource
    private RoomTypeDao roomTypeDao;

    @Override
    public BigDecimal getPrice(Long roomTypeId, LocalDate date) {
        RoomPrice roomPrice = new RoomPrice();
        roomPrice.setRoomTypeId(roomTypeId);
        roomPrice.setDate(date);

        RoomPrice result = roomPriceDao.selectByTypeAndDate(roomPrice);
        if (result == null) {
            return roomTypeDao.selectById(roomTypeId).getBasePrice();
        }

        return result.getPrice();
    }

}
